# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/27 11:31 
@Author  : ZhangShenao 
@File    : simple_chain.py 
@Desc    : 自定义简单的执行链
"""
from typing import Any


class Chain:
    """自定义执行链"""

    steps: list = []  # 存储执行链的步骤

    def __init__(self, steps):
        """
        初始化执行链
        :param steps: 执行链的步骤
        """
        self.steps = steps

    def invoke(self, input: Any) -> Any:
        """执行链,获取执行结果"""
        output = input

        # 调用链的每一步,将上一步的output作为下一步的input
        for s in self.steps:
            print(f'执行步骤: {s.__class__.__name__}')
            print(f'当前输入: {output}')
            output = s.invoke(output)
            print(f'执行结果: {output}')

        # 返回最终结果
        return output
